/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pos.beans;

import abstractClasses.AbstractListadoEntidades;
import entities.Ticket;
import entities.Usuario;
import facades.TicketFacade;
import facades.TipoTicketFacade;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import pos.qualifiers.EventoIrANuevoTicket;
import pos.qualifiers.EventoNuevoTicketAPartirDeReserva;
import qualifiers.UsuarioLogeado;

/**
 *
 * @author damfercer
 */
@Named(value = "listadoTicketsBean")
@SessionScoped
public class ListadoTicketsBean extends AbstractListadoEntidades<Ticket, TicketFacade> implements Serializable {
    @Inject
    @UsuarioLogeado
    Usuario usuario;
    @Inject
    @EventoIrANuevoTicket
    private Event<String> eventoIrNuevoTicket;
    @Inject
    @EventoNuevoTicketAPartirDeReserva 
    Event<Ticket>eventoTicketReserva;
    @Inject
    private TipoTicketFacade tipoTicektFacade;
    /**
     * Creates a new instance of ListadoTicketsBean
     */
    public ListadoTicketsBean() {
    }
    
    @PostConstruct
    @Override
    public void init(){
        setFacade(getEntityFacadeInstance().get());
        setListadoEntidades(getFacade().findByTiendasDeUsuario(usuario));
    }
    
    public String irANuevoTicket(){
        eventoIrNuevoTicket.fire("");
        return "/views/pos/NuevoTicket?faces-redirect=true";
    }
    public String irANuevaDevolucion(){
        eventoIrNuevoTicket.fire("");
        return "/views/pos/NuevaDevolucion?faces-redirect=true";
    }
    
    public String irANuevaReserva(){
        eventoIrNuevoTicket.fire("");
        return "/views/pos/NuevoTicketReserva?faces-redirect=true";
    }
    
    public String irANuevoTicketAPartirDeReserva(){
        eventoTicketReserva.fire(getEntidadElegida());
        return "/views/pos/NuevoTicketAPartirDeReserva?faces-redirect=true";
    }
    
    public Boolean getPuedeCrearTicketAPartirDeReserva(){
        Boolean puede=getEntidadElegida()!=null && getEntidadElegida().getTipoTicket().equals(tipoTicektFacade.getTipoTicketReserva()) && (getEntidadElegida().getTicketList()==null || getEntidadElegida().getTicketList().isEmpty());
        return puede;
    }
}
